From: Kunal Mehta Date: Sat, 8 Jul 2017 07:14:13 +0000 (-0700) Subject: parserTests: Improve class name guessing for PHPUnit X-Git-Tag: 1.31.0-rc.0~2266 X-Git-Url: http://git.cyclocoop.org/%27%20.%20%24prefix%20.%20Wiki::transformTitleToURI%28%24matches%5B1%5D%29%20.%20%27?a=commitdiff_plain;h=6eba88f24c30d8c2ba57d1e35b094099af164ad5;p=lhc%2Fweb%2Fwiklou.git parserTests: Improve class name guessing for PHPUnit Since we know the extension name, actually use it instead of trying to guess it based on the directory name. The new directory layout for autodiscovery encourages "tests/parser" so the directory one level up is unlikely to be the extension name. Change-Id: I352944a84197acba6fe425b6044b17c520e263d7 --- diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index 97c3c05b43..0dab130d04 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -182,13 +182,18 @@ class ParserTestRunner { if ( !file_exists( $dir ) ) { continue; } + $counter = 1; $dirIterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir ) ); foreach ( $dirIterator as $fileInfo ) { /** @var SplFileInfo $fileInfo */ if ( substr( $fileInfo->getFilename(), -4 ) === '.txt' ) { - $files[] = $fileInfo->getPathname(); + $name = $info['name'] . $counter; + while ( isset( $files[$name] ) ) { + $name = $info['name'] . '_' . $counter++; + } + $files[$name] = $fileInfo->getPathname(); } } } diff --git a/tests/phpunit/suites/ParserTestTopLevelSuite.php b/tests/phpunit/suites/ParserTestTopLevelSuite.php index 09052f3c61..4ea1090f6e 100644 --- a/tests/phpunit/suites/ParserTestTopLevelSuite.php +++ b/tests/phpunit/suites/ParserTestTopLevelSuite.php @@ -82,15 +82,15 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite { # Filter out .txt files $files = ParserTestRunner::getParserTestFiles(); - foreach ( $files as $parserTestFile ) { + foreach ( $files as $extName => $parserTestFile ) { $isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) ); if ( $isCore && $wantsCore ) { self::debug( "included core parser tests: $parserTestFile" ); - $filesToTest[] = $parserTestFile; + $filesToTest[$extName] = $parserTestFile; } elseif ( !$isCore && $wantsRest ) { self::debug( "included non core parser tests: $parserTestFile" ); - $filesToTest[] = $parserTestFile; + $filesToTest[$extName] = $parserTestFile; } else { self::debug( "skipped parser tests: $parserTestFile" ); } @@ -100,12 +100,13 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite { $testList = []; $counter = 0; - foreach ( $filesToTest as $fileName ) { - // Call the highest level directory the extension name. - // It may or may not actually be, but it should be close - // enough to cause there to be separate names for different - // things, which is good enough for our purposes. - $extensionName = basename( dirname( $fileName ) ); + foreach ( $filesToTest as $extensionName => $fileName ) { + if ( is_int( $extensionName ) ) { + // If there's no extension name because this is coming + // from the legacy global, then assume the next level directory + // is the extension name (e.g. extensions/FooBar/parserTests.txt). + $extensionName = basename( dirname( $fileName ) ); + } $testsName = $extensionName . '__' . basename( $fileName, '.txt' ); $parserTestClassName = ucfirst( $testsName );